package exception;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 异常处理机制在IO操作中的运用
 * */
public class FinallyDemo2 {
    public static void main(String[] args) {
        System.out.println("程序开始...");
        FileOutputStream fos = null;
        try{
            fos = new FileOutputStream(".a/asd.txt");
            fos.write(1);
        }catch(IOException e){
            System.out.println("出现了IO操作异常并处理了");
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                //e.printStackTrace();//Exception in thread "main" java.lang.NullPointerException       at exception.FinallyDemo2.main(FinallyDemo2.java:22)
                System.out.println("关闭流时出现了异常并解决了");
            }
        }
        System.out.println("程序结束...");

    }
}
